﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.OleDb;

namespace DAO
{
    class NVDAO
    {
        public List<NhanVienDTO> LayDSNhanVien()
        {
            string sql = "SELECT MaNV,HoTen,NgaySinh,GioiTinh,DiaChi,DienThoai,Diem,HeSo FROM NhanVien";
            OleDbConnection conn = DataProvider.ConnectDB();
            OleDbCommand cmd = new OleDbCommand(sql, conn);
            OleDbDataReader reader = cmd.ExecuteReader();
            List<NhanVienDTO> danhSach = new List<NhanVienDTO>();
            while (reader.Read())
            {
                NhanVienDTO nvDTO = new NhanVienDTO();
                nvDTO.MaNV = reader.GetInt32(0);
                nvDTO.HoTen = reader.GetString(1);
                nvDTO.NgaySinh = reader.GetDateTime(2);
                nvDTO.GioiTinh = reader.GetString(3);
                nvDTO.DiaChi = reader.GetString(4);
                nvDTO.DienThoai = reader.GetString(5);
                var nvdiem = reader.GetValue(6);
                nvDTO.Diem = nvdiem == DBNull.Value ? 0 : (int)nvdiem;
                nvDTO.HeSo = reader.GetInt32(7);
                danhSach.Add(nvDTO);
            }
            conn.Close();
            return danhSach;
        }
    }
}
